# -*- coding:utf-8 -*-

class ExtractionData:
    def extraction_data(self, weather_json):
        '从原始Json中抽取有用信息'
        if (weather_json == None):
            return None
        else:
            results_dict = weather_json['results']
            location_dict = results_dict[0]['location']
            daily_dict = results_dict[0]['daily']
            return location_dict, daily_dict


if __name__ == '__main__':
    data = {'results': [{'location': {'id': 'WQJ6YY8MHZP0', 'name': '西安', 'country': 'CN', 'path': '西安,西安,陕西,中国',
                                      'timezone': 'Asia/Shanghai', 'timezone_offset': '+08:00'}, 'daily': [
        {'date': '2022-08-23', 'text_day': '多云', 'code_day': '4', 'text_night': '多云', 'code_night': '4', 'high': '33',
         'low': '23', 'rainfall': '0.00', 'precip': '0.00', 'wind_direction': '东', 'wind_direction_degree': '90',
         'wind_speed': '8.4', 'wind_scale': '2', 'humidity': '80'},
        {'date': '2022-08-24', 'text_day': '多云', 'code_day': '4', 'text_night': '小雨', 'code_night': '13', 'high': '28',
         'low': '21', 'rainfall': '1.39', 'precip': '0.38', 'wind_direction': '东北', 'wind_direction_degree': '45',
         'wind_speed': '23.4', 'wind_scale': '4', 'humidity': '62'},
        {'date': '2022-08-25', 'text_day': '小雨', 'code_day': '13', 'text_night': '小雨', 'code_night': '13', 'high': '22',
         'low': '21', 'rainfall': '15.63', 'precip': '0.96', 'wind_direction': '东北', 'wind_direction_degree': '45',
         'wind_speed': '3.0', 'wind_scale': '1', 'humidity': '99'}], 'last_update': '2022-08-23T08:00:00+08:00'}]}

    e = ExtractionData()
    print(e.extraction_data(data))
